﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Helpers" %>
<%@ Import Namespace="WebHoiChoMuaBan.Models" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Utility" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Product
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadHolder" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            //            $("#Pages").change(function () {
            //                $.get("/AdminNews/Index",
            //                   { index: $(this).val() },
            //                   function (data) {
            //                       var selectedPage = $("#Pages").val();
            //                       var newsTypeId = $("#newsTypeId").val();
            //                       window.location = "/AdminNews/Index?selectedPage=" + selectedPage + "&newsTypeId=" + newsTypeId;
            //                   });
            //            });

            // Check and Uncheck all combobox
            $("#checkbox_all").click(function () {
                var n = $("#checkbox_all:checked").length;
                if (n == 1) {
                    $(".input_checkbox:not(#checkbox_news,#checkbox_member,#checkbox_product)").attr('checked', true);
                }
                else
                    $(".input_checkbox:not(#checkbox_news,#checkbox_member,#checkbox_product)").attr('checked', false);
            });

        });
    </script>
    <script type="text/javascript">
        function changeState(obj) {
            $.ajax({
                type: "POST",
                url: "/AdminProduct/ChangeProductState",
                data: "id=" + obj,
                success: function (result) {
                    alert("thành công");
                },
                error: function (req, status, error) {

                }
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%string session  = (string)ViewData["Session"]; %>
    <form action="<%= Url.Action("Controller","AdminProduct") %>" method="post" enctype="multipart/form-data"
    id="frm_Product">
    <input type="hidden" id="hidCmd" name="hidCmd" />
    <div class="hoicho_content_maingroup">
        <div class="col_left hoicho_marin_leftright content_right">
            <div class="content_group">
                <div class="col_left content_group hoicho_margin_topbottom">
                    <div class="private_button_upload col_left">
                        <a href="photo_dangtai_private.html">
                            <img src="/../Content/Images/icon_plus_up.gif">
                            Thành viên đăng</a>
                    </div>
                    <div class="private_button_upload col_left hoicho_margin_leftright">
                        <a href="photo_dangtai_private.html">
                            <img src="/../Content/Images/icon_plus_up.gif">
                            Admin đăng</a>
                    </div>
                    <div class="private_button_upload col_left hoicho_margin_leftright">
                        <a href="photo_dangtai_private.html">
                            <img src="/../Content/Images/icon_plus_up.gif">
                            Đăng sản phẩm</a>
                    </div>
                </div>
                <div class="content_group">
                    <div class="col_right hoicho_margin_topbottom">
                        <div class="col_left hoicho_margin_leftright font_bold">
                            <%
                            
                            %>
                        </div>
                        <div class="private_button_upload col_left hoicho_margin_leftright">
                            <a href="javascript:void(0)" onclick="SubmitData_Ajax('frm_Product', 'del'); return false;"
                                name="Delete">
                                <img src="<%=ResolveUrl("~/Content/Images/icon_plus_up.gif") %>" alt="" />Xóa
                            </a>
                        </div>
                        <div class="private_button_upload col_left">
                            <a href="javascript:void(0)" onclick="SubmitData_Ajax('frm_Product','ChangeState'); return false;"
                                name="ChangeState">
                                <img src="<%=ResolveUrl("~/Content/Images/icon_plus_up.gif") %>" alt="" />
                                Chuyển trạng thái</a>
                        </div>
                        <div class="private_button_upload col_left hoicho_margin_leftright">
                            <a href="photo_dangtai_private.html">
                                <img src="/../Content/Images/icon_plus_up.gif">
                                Cắt</a>
                        </div>
                        <div class="private_button_upload col_left">
                            <a href="photo_dangtai_private.html">
                                <img src="/../Content/Images/icon_plus_up.gif">
                                Dán</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="private_group_friend">
                <div class="col_left hoicho_margin_leftright font_bold">
                    <%
                        NewsProductHelper.FetchProductResult lstNews = (NewsProductHelper.FetchProductResult)ViewData["ListNewsProduct"];
                        int p;
                        int cateId = ViewData["CateId"] == null ? 0 : int.Parse(ViewData["CateId"].ToString());
                        if (Request.QueryString["p"] == null && !int.TryParse(Request.QueryString["p"], out p))
                        //if(p!=0)
                        {
                            p = 1;
                        }
                        else p = int.Parse(Request.QueryString["p"]);
                    %>
                    <% if (p > 1)
                       { %><a href='<%=string.Format("{0}?p={1}&cateId={2}'",
                                                                Url.Action(session, "AdminProduct"),
                                                                p-1,cateId) %>'><img src="/../Content/Images/arrow_breakpage_left.gif" alt="">&nbsp;Trang
                           trước</a>
                    <% } %>
                    <%
                        if (p > 3)
                            Response.Write(string.Format("<a href='{0}?p={1}&cateId={2}'{3}>{4}</a> ",
                                                            Url.Action(session, "AdminProduct"),
                                                            1,
                                                            cateId,
                                                            string.Empty,
                                                             1));
                        if (p > 4)
                            Response.Write("...");
                        int total = lstNews.totalPages;
                        int from = (p - 2 < 1 ? 1 : p - 2);
                        int to = (p + 2 >= total ? total : p + 2);
                        for (int i = from; i <= to; i++)
                            Response.Write(string.Format("<a href='{0}?p={1}&cateId={2}'{3}>{4}</a> ",
                                                            Url.Action(session, "AdminProduct"),
                                                            i, cateId,
                                                            (i == p ? "style='color:red'" : string.Empty),
                                                             i));
                        if (p <= total - 4)
                            Response.Write("...");
                        if (p <= total - 3)
                            Response.Write(string.Format("<a href='{0}?p={1}&cateId={2}'{3}>{4}</a> ",
                                                            Url.Action(session, "AdminProduct"),
                                                            total, cateId,
                                                            string.Empty,
                                                            total));
                    %>
                    <% if (p < lstNews.totalPages)
                       { %><a href='<%=string.Format("{0}?p={1}&cateId={2}'",
                                                                Url.Action(session, "AdminProduct"),
                                                                p+1,cateId) %>'>Trang sau&nbsp;<img src="/../Content/Images/arrow_breakpage_right.gif"
                                                                    alt=""></a>
                    <% } %>
                </div>
                <!-- DÙNG ĐỂ LƯU TRANG HIỆN TẠI VÀ GỬI VỀ SERVER ĐẺ MASK -->
                <input type="hidden" id="curPage" name="curPage" value="<%= p %>" />
                <table width="100%" border="0">
                    <tr bgcolor="#f5f7fb" class="border_bottom">
                        <td width="3%">
                            <input id="checkbox_all" class="input_checkbox" type="checkbox" name="checkbox_all" />
                        </td>
                        <td colspan="2">
                            <p class="font_bold">
                                Nội dung</p>
                        </td>
                        <td width="11%" align="center">
                            <span class="font_bold">Nổi bật</span>
                        </td>
                        <td width="2%" align="center">
                            <p class="font_bold">
                                &nbsp;</p>
                        </td>
                        <td width="2%" align="center">
                            <p class="font_bold">
                                &nbsp;</p>
                        </td>
                        <td width="11%" align="center">
                            <span class="font_bold">Người đăng</span>
                        </td>
                        <td width="9%" align="center">
                            <span class="font_bold">Link</span>
                        </td>
                        <td width="9%" align="center">
                            <span class="font_bold">Ngày gửi</span>
                        </td>
                    </tr>
                    <%
                        if (ViewData["ListNewsProduct"] != null)
                        {

                            int i = 0;
                            //List<NewsProduct> listNewsProduct = (List<NewsProduct>)ViewData["ListNewsProduct"];
                            foreach (NewsProduct item in lstNews.products)
                            {
                                if (i % 2 == 0)
                                    Response.Write("<tr>");
                                else
                                    Response.Write("<tr bgcolor='#E6E6E6'>");
                                Response.Write("<td valign='middle'><input class='input_checkbox' id='checkbox' name='checkbox' type='checkbox' value='" + item.NProId + "'/></td>");
                                Response.Write("<td width='3%' valign='middle'><img src='/../Content/Images/avatar_admin.png' width='40px' height='41px' alt='avatar admin'></td>");
                                Response.Write("<td width='57%' valign='middle'><p class='font_bold'>" + item.NProTitle + "</p>");
                                Response.Write("<p>" + item.NProIntro + "</p></td>");
                    %>
                    <td>
                        <center>
                            <%
                        string nicon, nmsg, nactionUrl;
               
                        if (item.isHotNewsProduct == 1)
                        {
                            nicon = "ui-icon-check";
                            nmsg = "Đang nổi bật! Nhấn nút để hủy thiết lập";
                            nactionUrl = "UnHot";
                        }
                        else
                        {
                            nicon = "ui-icon-locked";
                            nmsg = "Đang không nổi bật. Hãy nhấn nút để Kích hoạt";
                            nactionUrl = "Hot";
                        }
                            %>
                            <a href="/AdminProduct/<%=nactionUrl %>?id=<%=item.NProId %>" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only"
                                title="<%=nmsg %>"><span class="ui-button-icon-primary ui-icon <%=nicon %> "></span>
                                <span class="ui-button-text">Button with icon only</span> </a>
                        </center>
                    </td>
                    <td>
                        <center>
                            <%
string icon, msg, actionUrl;
if (item.NProState == true)
{
    icon = "ui-icon-check";
    msg = "Đang kích hoạt. Hãy nhấn nút để Khóa";
    actionUrl = "Lock";
}
else
{
    icon = "ui-icon-locked";
    msg = "Đang bị khóa. Hãy nhấn nút để Kích hoạt";
    actionUrl = "Lock";
}
                            %>
                            <a href="/AdminProduct/<%=actionUrl %>?id=<%=item.NProId %>" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only"
                                title="<%=msg %>"><span class="ui-button-icon-primary ui-icon <%=icon %> "></span>
                                <span class="ui-button-text">Button with icon only</span> </a>
                        </center>
                    </td>
                    <%
Response.Write("<td align='center' valign='middle'><a href='" + Url.Action("DeleteProduct", "AdminProduct", new { productId = item.NProId }) + "'> <img src='/../Content/Images/icon_delete.png' alt=''/></a></td>");
Response.Write("<td align='center' valign='middle'>" + item.Member.MemUsername + "</td>");
Response.Write("<td align='center' valign='middle'>");

Response.Write("<div class='private_button_upload col_left'><a href='#'><img src='/../Content/Images/icon_plus_up.gif' />");

if (!item.NProState)
{
                    %>
                    <a href="" onclick="changeState(<%=item.NProId %>)">
                        <img src="<%=ResolveUrl("~/Content/Images/icon_plus_up.gif") %>" alt="" />
                        Chuyển trạng thái</a>
                    <%
}
else
{
    Response.Write("<span class='font_bold'><a href='/AdminProduct/Revising?id=" + item.NProId + "'>Link</a></span>");
    Response.Write("<br/>");
    Response.Write("<span class='font_bold'><a href='/AdminProduct/EditProduct?uid=" + Session["Memid"] + "&productId=" + item.NProId + "'>Update</a></span>");
}
                                
                    %>
                    <%
                        Response.Write("</a></div>");
                        Response.Write("</td>");
                        Response.Write("<td align='center' valign='middle'><span class='font_bold'>" + item.NProDate.ToString("dd/MM/yyyy") + "</span></td>");
                        Response.Write("</tr>"); i++;
                            }
                        }
                        else { Response.Write("<tr><td>Chưa có sản phẩm được đăng</td></tr>"); } %>
                </table>
                <div class="col_left hoicho_margin_leftright font_bold">
                    <%
                        if (Request.QueryString["p"] == null && !int.TryParse(Request.QueryString["p"], out p))
                        //if(p!=0)
                        {
                            p = 1;
                        }
                        else p = int.Parse(Request.QueryString["p"]);
                    %>
                    <% if (p > 1)
                       { %><a href='<%=string.Format("{0}?p={1}&cateId={2}'",
                                                                Url.Action(session, "AdminProduct"),
                                                                p-1,cateId) %>'><img src="/../Content/Images/arrow_breakpage_left.gif" alt="">&nbsp;Trang
                           trước</a>
                    <% } %>
                    <%
                        if (p > 3)
                            Response.Write(string.Format("<a href='{0}?p={1}&cateId={2}'{3}>{4}</a> ",
                                                            Url.Action(session, "AdminProduct"),
                                                            1,
                                                            cateId,
                                                            string.Empty,
                                                             1));
                        if (p > 4)
                            Response.Write("...");
                        total = lstNews.totalPages;
                        from = (p - 2 < 1 ? 1 : p - 2);
                        to = (p + 2 >= total ? total : p + 2);
                        for (int i = from; i <= to; i++)
                            Response.Write(string.Format("<a href='{0}?p={1}&cateId={2}'{3}>{4}</a> ",
                                                            Url.Action(session, "AdminProduct"),
                                                            i, cateId,
                                                            (i == p ? "style='color:red'" : string.Empty),
                                                             i));
                        if (p <= total - 4)
                            Response.Write("...");
                        if (p <= total - 3)
                            Response.Write(string.Format("<a href='{0}?p={1}&cateId={2}'{3}>{4}</a> ",
                                                            Url.Action(session, "AdminProduct"),
                                                            total, cateId,
                                                            string.Empty,
                                                            total));
                    %>
                    <% if (p < lstNews.totalPages)
                       { %><a href='<%=string.Format("{0}?p={1}&cateId={2}'",
                                                                Url.Action(session, "AdminProduct"),
                                                                p+1,cateId) %>'>Trang sau&nbsp;<img src="/../Content/Images/arrow_breakpage_right.gif"
                                                                    alt=""></a>
                    <% } %>
                </div>
                <br />
            </div>
        </div>
        <div class="col_right hoicho_margin_topbottom">
            <div class="private_button_upload col_left hoicho_margin_leftright">
                <a href="javascript:void(0)" onclick="SubmitData_Ajax('frm_Product', 'del'); return false;"
                    name="Delete">
                    <img src="<%=ResolveUrl("~/Content/Images/icon_plus_up.gif") %>" alt="" />Xóa
                </a>
            </div>
            <div class="private_button_upload col_left">
                <a href="javascript:void(0)" onclick="SubmitData_Ajax('frm_Product','ChangeState'); return false;"
                    name="ChangeState">
                    <img src="<%=ResolveUrl("~/Content/Images/icon_plus_up.gif") %>" alt="" />
                    Chuyển trạng thái</a>
            </div>
            <div class="private_button_upload col_left hoicho_margin_leftright">
                <a href="photo_dangtai_private.html">
                    <img src="/../Content/Images/icon_plus_up.gif">
                    Cắt</a>
            </div>
            <div class="private_button_upload col_left">
                <a href="photo_dangtai_private.html">
                    <img src="/../Content/Images/icon_plus_up.gif">
                    Dán</a>
            </div>
        </div>
    </div>
    <!-- End Content right -->
    </div>
    </form>
</asp:Content>
